package com.etc.servcie;

import com.etc.dao.EmpMapper;
import com.etc.pojo.EmpPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

// 业务逻辑
@Service
@Transactional
public class EmpService {

    @Autowired
    EmpMapper mapper;


    public List<HashMap> fsafa() {
        return mapper.getAll();
    }

    // 1. 只要有异常我就回滚
    // 2. isolation 事务隔离级别
    // 3. 事务传播机制
    //  a()中调用 b()中调用 c()  每个方法都有CUD a(),b(),c() :是否要在一个事务中
    @Transactional(rollbackFor = Exception.class, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public void add(EmpPojo emp) {
        int result = mapper.insertdata(emp);
        // keyProperty="id" useGeneratedKeys="true" 获取刚插入的ID
        System.out.println(emp.getId());
        System.out.println(result); // 插入条数 // TODO获刚插入id

        mapper.insertdata(emp);
        System.out.println(emp.getId());
        System.out.println(result); // 插入条数 // TODO获刚插入id
        throw new NullPointerException("随便报一场");
    }

    public List<HashMap> xxxxx(HashMap param) {
        return mapper.zonghechaxun(param);
    }
}
